<?php
/**
 *    Expectation for the Equal Assertion
 */

class Expectation_Equal extends Expectation{
    private $value;

    /**
     *    Sets the value to compare against.
     *    @param mixed $value        Test value to match.
     *    @param string $message     Customised message on failure.
     *    @access public
     */
    function __construct($value) {
        parent::__construct();
        $this->value = trim($value);
    }

    /**
     *    Tests the expectation. True if it matches the
     *    held value.
     *    @param mixed $compare        Comparison value.
     *    @return boolean              True if correct.
     *    @access public
     */
    function test($compare) {
        $this->compareResult= (($this->value == $compare) && ($compare == $this->value));
        return $this->compareResult;
    }

    /**
     *    Returns a human readable test message.
     *    @param mixed $compare      Comparison value.
     *    @return string             Description of success
     *                               or failure.
     *    @access public
     */
    function testMessage($compare) {
        $dumper = $this->getDumper();
        if ($this->compareResult) {
            return "Equal expectation [" . $dumper->describeValue($this->value) . "]";
        } else {
            return "Equal expectation fails " .
                    $dumper->describeDifference($this->value, $compare);
        }
    }

    /**
     *    Accessor for comparison value.
     *    @return mixed       Held value to compare with.
     *    @access protected
     */
    protected function getValue() {
        return $this->value;
    }
}
?>
